package CreationalPattern.simpleFruitFactory;

import CreationalPattern.XMLUtil;

public class FruitFactory {
    // 静态工厂方法
    public static FruitProduct getProduct(String name) {
        if (name.equalsIgnoreCase("A")) {
            return new Apple();
        } else if (name.equalsIgnoreCase("P")) {
            return new Pear();
        } else {
            return null;
        }
    }

    public static void main(String[] args) {
        FruitProduct fruitProduct = FruitFactory.getProduct(XMLUtil.getFruitType());
        if (fruitProduct != null) {
            fruitProduct.methodsame();
            fruitProduct.methoddiff();
        }
    }
}
